/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * newVisit.java
 *
 * Created on Jan 1, 2009, 6:38:57 PM
 */
package GUI;

import Dictionary.Dictionary;
import GUI.other.fastDiagAdd;
import GUI.other.fastOperAdd;
import functions.Diagnoses;
import functions.Dogs;
import functions.Dogy;
import functions.Drugs;
import functions.HealingSet;
import functions.Healings;
import functions.ItemList;
import functions.Items;
import functions.Operations;
import functions.Visits;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.sql.Date;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;
import model.Database;
import model.Diagnose;
import model.Doctor;
import model.Dog;
import model.Drug;
import model.Item;
import model.Operation;
import model.Sklad_drugs;
import model.User;
import model.Visit;
import stuff.CellRenderer;
import stuff.DrugPriceCellEditor;
import stuff.DrugPriceRenderer;
import stuff.FDate;
import stuff.FormException;
import stuff.TableButtonEditor;
import stuff.TableButtonRenderer;

/**
 *
 * @author JArik
 */
public class NewVisit extends javax.swing.JFrame {

    /** Creates new form newVisit */
    private MainFrame mainFrame;
    private User user;
    private Dog selDog;
    private HealingSet healingSet;
    private Item choosenItem;
    private Diagnose choosenDiag;
    private Operation choosenOper;
    private String nameText="",
                   diagText="",
                   operText="",
                   healingResultText="",
                   visitDateText="",
                   healingNameText="";
    private ItemList visit;
    private JTextField activeField;
    private double totalPrice = 0, totalPayed= 0;
    private TreeMap press;
    private ArrayList<Drug> visitDrugs;
    private ArrayList<Operation> visitOpers;
    private ArrayList<Diagnose> visitDiags;
    private Visit visitInfo;
    private UserCard parentWindow;
    private boolean toChange=false;
    public NewVisit(MainFrame frame, User us, Dog dg, HealingSet hs, ItemList vis) {

        initComponents();
        currencyComboBox.setModel(new javax.swing.DefaultComboBoxModel(Dogy.CURRENCY));
        mainFrame = frame;
        user = us;
        selDog = dg;
        healingSet = hs;
        visit = vis;
        if(visit != null)
            toChange = true;
        this.setTitle("Новый Визит - " + us.getSurname());

        //Dogy.reSizeAndCenter(this);
        Dogy.reSize(this);
        Dogy.placeToCenter(this);
        
        try {
            ArrayList types = Drugs.getTypes();
            types.add(0, "Всё");
            types.add(1, Dictionary.DRUGS);
            types.add(2, Dictionary.OTHER);
            typeBox.setModel(new javax.swing.DefaultComboBoxModel(types.toArray()));
            typeBox.setSelectedIndex(0);
        } catch (SQLException ex) {
            mainFrame.SQLException(ex);
        }
        /*userInfo.setText(us.getName() + "\n" + us.getStreet() +
                (us.getTel().isEmpty() ? "" : "\n" + us.getTel() + "\n"));*/

        operText = "Введите название операции(F5)";
        diagText = "Введите название диагноза(F3)";
        healingNameText ="Название курса";
        nameText = "Введите название предмета или лекарства(F4)";
        healingResultText = Dictionary.COURSE_RESULT;
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
        visitDateText = sdf.format(Calendar.getInstance().getTime());
        visitDateField.setText(visitDateText);
        nameBox.setText(nameText);
        operBox.setText(operText);
        healingResultField.setText(healingResultText);
        healingResultField.setForeground(Color.gray);
        operBox.setForeground(Color.gray);
        healingNameField.setForeground(Color.gray);
        nameBox.setForeground(Color.gray);
        diagBox.setForeground(Color.gray);
        boxPopup.add(boxList);
        boxPopup.pack();

        fillDogTable();
        // new visit
        if (healingSet != null) {
            fillHealingDiagTable();
            fillHealingDrugsTable();
            fillHealingOperTable();
            //healingInfo.requestFocus();
            if(healingSet.getResult() != null && !healingSet.getResult().isEmpty())
            {
                healingResultField.setText(healingSet.getResult());
                healingResultField.setForeground(Color.black);
            }
            visitTabs.setSelectedIndex(1);
            healingInfo.add(Dictionary.HEALING_COURSE,newHealingPanel);
            healingNameField.setText(healingSet.getName());
            setHealingNameButton.setVisible(false);
        // new treatment course
        } else {
            healingPanel.removeAll();
            healingPanel.setLayout(new GridLayout());
            healingPanel.add(newHealingPanel);
            pack();
            repaint();
            healingNameField.requestFocus();
        }
        
        if (visit != null)
        {
            visitDrugs = new ArrayList<Drug>();
            visitOpers = new ArrayList<Operation>();
            visitDiags = new ArrayList<Diagnose>();

            for (int i = 0; i < visit.size(); i++) {
                if (visit.get(i) instanceof Drug ) {
                    if(!((Drug) visit.get(i)).isDeleted())
                    {
                      visitDrugs.add((Drug) visit.get(i));
                      this.addToDrugTable((Drug) visit.get(i));
                    }
                }
                if (visit.get(i) instanceof Operation) {
                    if(!((Operation) visit.get(i)).isDeleted())
                    {
                      visitOpers.add((Operation) visit.get(i));
                      this.addToOperTable((Operation) visit.get(i));
                    }
                }
                if (visit.get(i) instanceof Diagnose) {
                    if(!((Diagnose) visit.get(i)).isDeleted())
                    {
                      visitDiags.add((Diagnose) visit.get(i));
                      this.addToDiagTable((Diagnose) visit.get(i),
                            !((Diagnose) visit.get(i)).isPredv());
                    }
                }
                if (visit.get(i) instanceof Visit) {
                    visitInfo = (Visit) visit.get(i);

                    currencyComboBox.setSelectedItem(visitInfo.getCurrency());
                    visitDescrField.setText(visitInfo.getDescr());
                    visitRecomField.setText(visitInfo.getRecom());
                    visitPriceField.setText(visitInfo.getSellPrice() + "");
                    visitPricePayedField.setText(visitInfo.getVisitPayed()+"");
                    visitOtherPricePayedField.setText(visitInfo.getVisitOtherPayed()+"");
                    visitOtherPriceField.setText(visitInfo.getOtherPrice() +"");
                    statusField.setSelectedItem(visitInfo.getStatus());
                    payedByCard.setSelected(visitInfo.isCardPayment());
                    //TODO visitOtherPriceField.setText(visi.get);
                    FDate date = new FDate(visitInfo.getDisDate().getTime());
                    visitDateField.setText(date + "");
                    fillDocField(visitInfo.getDoctor());
                }
            }
          calculateTotal();
          if(selDog.isDead())
              dogDeathDate.setText( sdf.format(selDog.getDeathDate()));
        } else
          fillDocField(mainFrame.getManager().getDoctor());


        KeyStroke ctrlW = KeyStroke.getKeyStroke(KeyEvent.VK_W,2);
        InputMap map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(ctrlW, "ctrlW");
        ActionMap actionMap = visitTabs.getActionMap();
        actionMap.put("ctrlW", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                        ((javax.swing.JFrame)visitTabs.getRootPane().getParent()).dispose();
                     }
             });
        KeyStroke keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_F2,0);
        map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(keyStr, "f2");
        actionMap = visitTabs.getActionMap();
        actionMap.put("f2", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         visitTabs.requestFocus();
                        visitTabs.setSelectedIndex(1);
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_F1,0);
        map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(keyStr, "f1");
        actionMap = visitTabs.getActionMap();
        actionMap.put("f1", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         visitTabs.requestFocus();
                         visitTabs.setSelectedIndex(0);
                         if(healingInfo.isVisible())
                             healingInfo.requestFocus();
                         else
                             healingNameField.requestFocus();
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_K,2);
        map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(keyStr, "ctrkK");
        actionMap = visitTabs.getActionMap();
        actionMap.put("ctrkK", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         if(payedByCard.isSelected())
                             payedByCard.setSelected(false);
                         else
                             payedByCard.setSelected(true);
                     }
             });

       keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_F3,0);
        map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(keyStr, "f3");
        actionMap = visitTabs.getActionMap();
        actionMap.put("f3", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         visitTabs.requestFocus();
                        visitTabs.setSelectedIndex(2);
                        diagBox.requestFocus();
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_F4,0);
        map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(keyStr, "f4");
        actionMap = visitTabs.getActionMap();
        actionMap.put("f4", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         visitTabs.requestFocus();
                         visitTabs.setSelectedIndex(3);
                         nameBox.requestFocus();
                     }
             });

        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_F5,0);
        map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(keyStr, "f5");
        actionMap = visitTabs.getActionMap();
        actionMap.put("f5", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         visitTabs.requestFocus();
                         visitTabs.setSelectedIndex(4);
                         operBox.requestFocus();
                     }
             });

        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_F10,0);
        map = visitTabs.getInputMap(javax.swing.JTable.WHEN_IN_FOCUSED_WINDOW);
        map.put(keyStr, "f10");
        actionMap = visitTabs.getActionMap();
        actionMap.put("f10", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         addVisitActionPerformed(null);
                     }
             });

        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0);
        map = visitDescrField.getInputMap(javax.swing.JTable.WHEN_FOCUSED);
        map.put(keyStr, "tab");
        actionMap = visitDescrField.getActionMap();
        actionMap.put("tab", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         visitRecomField.requestFocus();
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_TAB,0);
        map = visitRecomField.getInputMap(javax.swing.JTable.WHEN_FOCUSED);
        map.put(keyStr, "tab");
        actionMap = visitRecomField.getActionMap();
        actionMap.put("tab", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         statusField.requestFocus();
                     }
             });
             //healingTab
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_1,0);
        map = healingInfo.getInputMap(javax.swing.JPanel.WHEN_FOCUSED);
        map.put(keyStr, "healing1");
        actionMap = healingInfo.getActionMap();
        actionMap.put("healing1", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         healingInfo.setSelectedIndex(0);
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_2,0);
        map = healingInfo.getInputMap(javax.swing.JPanel.WHEN_FOCUSED);
        map.put(keyStr, "healing2");
        actionMap = healingInfo.getActionMap();
        actionMap.put("healing2", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         healingInfo.setSelectedIndex(1);
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_3,0);
        map = healingInfo.getInputMap(javax.swing.JPanel.WHEN_FOCUSED);
        map.put(keyStr, "healing3");
        actionMap = healingInfo.getActionMap();
        actionMap.put("healing3", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         healingInfo.setSelectedIndex(2);
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,0);
        map = drugTable.getInputMap(javax.swing.JPanel.WHEN_FOCUSED);
        map.put(keyStr, "drugEd");
        actionMap = drugTable.getActionMap();
        actionMap.put("drugEd", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         int row = drugTable.getSelectedRow(),
                             column = drugTable.getSelectedColumn();
                         drugTable.editCellAt(row,column);
                         if(column == 1)
                         {
                          DrugPriceCellEditor dpe = (DrugPriceCellEditor) drugTable.getCellEditor(
                                 row, 1);
                          dpe.requestFocus();
                         }else
                         {
                             drugTable.getCellEditor(
                                 row, column).
                                 getTableCellEditorComponent(drugTable, drugTable.getValueAt(row, column),
                                 true, row, column).requestFocus();
                         }
                     }
             });
        keyStr = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,0);
        map = operTable.getInputMap(javax.swing.JPanel.WHEN_FOCUSED);
        map.put(keyStr, "operEd");
        actionMap = operTable.getActionMap();
        actionMap.put("operEd", new AbstractAction() {
                     public void actionPerformed(ActionEvent actionEvent)
                     {
                         int row = operTable.getSelectedRow(),
                             column = operTable.getSelectedColumn();
                         operTable.editCellAt(row,column);
                             operTable.getCellEditor(
                                 row, column).
                                 getTableCellEditorComponent(operTable, operTable.getValueAt(row, column),
                                 true, row, column).requestFocus();
                         }
             });
        
        //visitTabs.requestFocus();
        /*if(healingSet != null)
          healingInfo.requestFocus();
        else
          healingNameField.requestFocus();*/
        pack();
    }

    public void fillDocField(Doctor doc)
    {
        try
        {
          ArrayList<Doctor> docs = functions.Doctors.getAll();
          docField.removeAllItems();
          for(int i=0; i< docs.size(); i++)
          {
              docField.addItem(docs.get(i));
              if(doc != null && doc.getId() == docs.get(i).getId())
                  docField.setSelectedItem(docs.get(i));
          }
        } catch(SQLException e)
        {
            mainFrame.SQLException(e);
        }
    }

    public void fillHealingDiagTable() {
        ArrayList<Diagnose> diags = healingSet.getDiagSummary();
        DefaultTableModel model = (DefaultTableModel) healingDiagTable.getModel();
        model.setRowCount(0);
        for (int i = 0; i < diags.size(); i++) {
            model.addRow(new Object[]{diags.get(i), diags.get(i).getType(),
                        diags.get(i)});
        }
        healingDiagTable.setModel(model);

    }

    public void fillHealingDrugsTable() {
        ArrayList<Drug> drugs = healingSet.getDrugSummary();
        DefaultTableModel model = (DefaultTableModel) healingDrugTable.getModel();
        model.setRowCount(0);
        for (int i = 0; i < drugs.size(); i++) {
            model.addRow(new Object[]{drugs.get(i), drugs.get(i).getAmount(),
                        drugs.get(i).getDisDate()});
        }
        healingDrugTable.setModel(model);
    }

    public void fillHealingOperTable() {
        ArrayList<Operation> opers = healingSet.getOperationSummary();
        DefaultTableModel model = (DefaultTableModel) healingOperTable.getModel();
        model.setRowCount(0);
        for (int i = 0; i < opers.size(); i++) {
            model.addRow(new Object[]{opers.get(i), opers.get(i).getDescr(),
                        opers.get(i).getDisDate()});
        }
        healingOperTable.setModel(model);
    }

    public void fillDogTable() {
        /*DefaultTableModel model = (DefaultTableModel) dogsTable.getModel();
        model.setRowCount(0);

        try {
            ArrayList<Dog> dogs = user.getDogs();
            int selId = 0;
            for (int i = 0; i < dogs.size(); i++)
            {
                model.addRow(new Object[]{dogs.get(i)});
                if (selDog != null && dogs.get(i).getId() == selDog.getId())
                   selId = i;
            }
            dogsTable.setModel(model);
            dogsTable.setRowSelectionInterval(selId, selId);
            Rectangle r = dogsTable.getCellRect(selId, 0, true);
            dogsTable.scrollRectToVisible(r);
            
        } catch (SQLException ex) {
            mainFrame.SQLException(ex);
        }*/
    }

    private void calculateTotal() {
        totalPrice = 0;
        totalPayed = 0;
        double visPrice = 0;
        double visPricePayed = 0;
        double visOther = 0;
        double visOtherPayed = 0;

        if(!visitPriceField.getText().isEmpty())
        visPrice = Double.parseDouble(visitPriceField.getText());
        if(!visitPricePayedField.getText().isEmpty())
        visPricePayed = Double.parseDouble(visitPricePayedField.getText());
        if(!visitOtherPriceField.getText().isEmpty())
        visOther = Double.parseDouble(visitOtherPriceField.getText());
        if(!visitOtherPricePayedField.getText().isEmpty())
        visOtherPayed = Double.parseDouble(visitOtherPricePayedField.getText());
        
        double lekarstva = 0;
        double lekPayed = 0;
        DefaultTableModel model  = (DefaultTableModel) drugTable.getModel();
        for(int i=0; i< model.getRowCount(); i++)
        {
            lekarstva += Double.parseDouble(model.getValueAt(i, 1).toString())*
                         Double.parseDouble(model.getValueAt(i, 3).toString());
            lekPayed +=  Double.parseDouble(model.getValueAt(i, 2).toString());
        }
        
        double oper=0;
        double operPayed=0;
        model = (DefaultTableModel) operTable.getModel();
        for(int i=0; i< model.getRowCount(); i++)
        {
            oper += Double.parseDouble(model.getValueAt(i, 1).toString());
            operPayed += Double.parseDouble(model.getValueAt(i, 2).toString());
        }
        
        totalPrice = visPrice + visOther + lekarstva + oper;
        totalPayed = visPricePayed + visOtherPayed + lekPayed + operPayed;
        totalPrice = Dogy.roundPrice(totalPrice);
        totalPayed = Dogy.roundPrice(totalPayed);
        totalPriceField.setText(totalPrice+"");
        totalPayedField.setText(totalPayed +"");
        if(totalPrice != totalPayed)
        {
            totalPriceField.setBorder(javax.swing.BorderFactory.createLineBorder(Color.red));
            totalPayedField.setBorder(javax.swing.BorderFactory.createLineBorder(Color.red));

        }else
        {
            totalPriceField.setBorder(javax.swing.BorderFactory.createLineBorder(Color.green));
            totalPayedField.setBorder(javax.swing.BorderFactory.createLineBorder(Color.green));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        boxPopup = new javax.swing.JPopupMenu();
        boxList = new javax.swing.JScrollPane();
        list = new javax.swing.JList();
        dialog = new javax.swing.JDialog();
        newHealingPanel = new javax.swing.JPanel();
        healingName = new javax.swing.JLabel();
        healingNameField = new javax.swing.JTextField();
        setHealingNameButton = new javax.swing.JButton();
        addVisit = new javax.swing.JButton();
        closeButton = new javax.swing.JButton();
        visitTabs = new javax.swing.JTabbedPane();
        healingTab = new javax.swing.JPanel();
        healingResultField = new javax.swing.JTextField();
        healingPanel = new javax.swing.JPanel();
        healingLabel = new javax.swing.JLabel();
        healingInfo = new javax.swing.JTabbedPane();
        jScrollPane8 = new javax.swing.JScrollPane();
        healingDiagTable = new javax.swing.JTable();
        jScrollPane9 = new javax.swing.JScrollPane();
        healingDrugTable = new javax.swing.JTable();
        jScrollPane10 = new javax.swing.JScrollPane();
        healingOperTable = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        visitPriceField = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        visitDescrField = new javax.swing.JTextPane();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        visitRecomField = new javax.swing.JTextPane();
        statusField = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        visitOtherPriceField = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        visitPricePayedField = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        visitOtherPricePayedField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        deathDatePanel = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        dogDeathDate = new javax.swing.JFormattedTextField();
        payedByCard = new javax.swing.JCheckBox();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        diagTable = new javax.swing.JTable();
        delDiag = new javax.swing.JButton();
        diagBox = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        drugTable = new javax.swing.JTable();
        nameBox = new javax.swing.JTextField();
        typeBox = new javax.swing.JComboBox();
        delItem = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        operTable = new javax.swing.JTable();
        delOper = new javax.swing.JButton();
        operBox = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        totalPriceField = new javax.swing.JFormattedTextField();
        totalPayedField = new javax.swing.JFormattedTextField();
        jLabel11 = new javax.swing.JLabel();
        docField = new javax.swing.JComboBox();
        visitDateField = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        currencyComboBox = new javax.swing.JComboBox();
        currencyLabel = new javax.swing.JLabel();

        boxPopup.setAutoscrolls(true);
        boxPopup.setMaximumSize(new java.awt.Dimension(490, 645555));
        boxPopup.setPreferredSize(new java.awt.Dimension(490, 120));

        boxList.setAutoscrolls(true);
        boxList.setMaximumSize(new java.awt.Dimension(520, 645555));
        boxList.setMinimumSize(new java.awt.Dimension(480, 120));
        boxList.setPreferredSize(new java.awt.Dimension(480, 120));

        list.setFont(new java.awt.Font("Tahoma", 0, 12));
        list.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Добавить новое" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        list.setMaximumSize(new java.awt.Dimension(490, 300));
        list.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                listMouseClicked(evt);
            }
        });
        boxList.setViewportView(list);

        dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        dialog.setResizable(false);
        dialog.setUndecorated(true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                dialogWindowClosed(evt);
            }
        });

        javax.swing.GroupLayout dialogLayout = new javax.swing.GroupLayout(dialog.getContentPane());
        dialog.getContentPane().setLayout(dialogLayout);
        dialogLayout.setHorizontalGroup(
            dialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        dialogLayout.setVerticalGroup(
            dialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        newHealingPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Создание нового курса", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(102, 102, 102))); // NOI18N

        healingName.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        healingName.setText("Укажите название курса:");

        healingNameField.setFont(new java.awt.Font("Tahoma", 0, 14));
        healingNameField.setText("Название курса");
        healingNameField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                healingNameFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                healingNameFieldFocusLost(evt);
            }
        });

        setHealingNameButton.setFont(new java.awt.Font("Tahoma", 1, 12));
        setHealingNameButton.setText("Вставить из диагнозов");
        setHealingNameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                setHealingNameButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout newHealingPanelLayout = new javax.swing.GroupLayout(newHealingPanel);
        newHealingPanel.setLayout(newHealingPanelLayout);
        newHealingPanelLayout.setHorizontalGroup(
            newHealingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newHealingPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(newHealingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(healingNameField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
                    .addComponent(healingName, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(setHealingNameButton, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        newHealingPanelLayout.setVerticalGroup(
            newHealingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(newHealingPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(healingName)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(healingNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(setHealingNameButton)
                .addContainerGap(28, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowFocusListener(new java.awt.event.WindowFocusListener() {
            public void windowGainedFocus(java.awt.event.WindowEvent evt) {
                formWindowGainedFocus(evt);
            }
            public void windowLostFocus(java.awt.event.WindowEvent evt) {
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                formComponentMoved(evt);
            }
        });

        addVisit.setFont(new java.awt.Font("Tahoma", 1, 14));
        addVisit.setText(Dictionary.SAVE_VISIT+"(F10)");
        addVisit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addVisitActionPerformed(evt);
            }
        });

        closeButton.setFont(new java.awt.Font("Tahoma", 1, 14));
        closeButton.setText(Dictionary.CLOSE+"(Ctrl+w)");
        closeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeButtonActionPerformed(evt);
            }
        });

        visitTabs.setFont(new java.awt.Font("Tahoma", 1, 16));
        visitTabs.setMinimumSize(new java.awt.Dimension(685, 340));
        visitTabs.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                visitTabsKeyTyped(evt);
            }
        });

        healingResultField.setFont(new java.awt.Font("Tahoma", 0, 14));
        healingResultField.setText("Результат курса");
        healingResultField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                healingResultFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                healingResultFieldFocusLost(evt);
            }
        });

        healingLabel.setFont(new java.awt.Font("Tahoma", 1, 13));
        healingLabel.setText("Общая информация по курсу:");

        healingInfo.setTabPlacement(javax.swing.JTabbedPane.BOTTOM);
        healingInfo.setFont(new java.awt.Font("Tahoma", 1, 13));

        healingDiagTable.setAutoCreateRowSorter(true);
        healingDiagTable.setFont(new java.awt.Font("Tahoma", 1, 12));
        healingDiagTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                Dictionary.NAMING,
                Dictionary.TYPE,
                ""
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        press = new TreeMap();
        healingDiagTable.getColumnModel().getColumn(2).setCellEditor(new TableButtonEditor("Добавить",healingDiagTable,press));
        healingDiagTable.getColumnModel().getColumn(2).setCellRenderer(new TableButtonRenderer("Добавить",press));
        healingDiagTable.setRowHeight(30);
        jScrollPane8.setViewportView(healingDiagTable);

        healingInfo.addTab(Dictionary.DIAGNOSES+"(1)", jScrollPane8);

        healingDrugTable.setAutoCreateRowSorter(true);
        healingDrugTable.setFont(new java.awt.Font("Tahoma", 1, 12));
        healingDrugTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                Dictionary.NAMING,
                Dictionary.AMOUNT,
                Dictionary.DATE
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Double.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        healingDrugTable.setRowHeight(30);
        jScrollPane9.setViewportView(healingDrugTable);

        healingInfo.addTab(Dictionary.DRUGS+"(2)", jScrollPane9);

        healingOperTable.setAutoCreateRowSorter(true);
        healingOperTable.setFont(new java.awt.Font("Tahoma", 1, 12));
        healingOperTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                Dictionary.NAMING,
                Dictionary.DESCR,
                Dictionary.DATE
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        healingOperTable.setRowHeight(30);
        jScrollPane10.setViewportView(healingOperTable);

        healingInfo.addTab(Dictionary.OPERATIONS+"(3)", jScrollPane10);

        javax.swing.GroupLayout healingPanelLayout = new javax.swing.GroupLayout(healingPanel);
        healingPanel.setLayout(healingPanelLayout);
        healingPanelLayout.setHorizontalGroup(
            healingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(healingInfo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
            .addGroup(healingPanelLayout.createSequentialGroup()
                .addComponent(healingLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(394, Short.MAX_VALUE))
        );
        healingPanelLayout.setVerticalGroup(
            healingPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(healingPanelLayout.createSequentialGroup()
                .addComponent(healingLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(healingInfo, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout healingTabLayout = new javax.swing.GroupLayout(healingTab);
        healingTab.setLayout(healingTabLayout);
        healingTabLayout.setHorizontalGroup(
            healingTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(healingTabLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(healingTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(healingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(healingResultField, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE))
                .addContainerGap())
        );
        healingTabLayout.setVerticalGroup(
            healingTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(healingTabLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(healingPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(healingResultField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        visitTabs.addTab(Dictionary.HEALING_COURSE, healingTab);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setText(Dictionary.VISIT_PRICE+":");

        visitPriceField.setFont(new java.awt.Font("Tahoma", 0, 14));
        visitPriceField.setText("0");
        visitPriceField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                visitPriceFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                visitPriceFieldFocusLost(evt);
            }
        });
        visitPriceField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                visitPriceFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                visitPriceFieldKeyReleased(evt);
            }
        });

        visitDescrField.setFont(new java.awt.Font("Tahoma", 0, 14));
        visitDescrField.setFocusCycleRoot(false);
        visitDescrField.setMaximumSize(new java.awt.Dimension(6, 21));
        visitDescrField.setNextFocusableComponent(visitRecomField);
        visitDescrField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                visitDescrFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                visitDescrFieldKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                visitDescrFieldKeyTyped(evt);
            }
        });
        jScrollPane2.setViewportView(visitDescrField);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel4.setText(Dictionary.DESCR+":");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel5.setText(Dictionary.RECOMMENDATIONS+":");

        visitRecomField.setFont(new java.awt.Font("Tahoma", 0, 14));
        visitRecomField.setMaximumSize(new java.awt.Dimension(6, 21));
        jScrollPane3.setViewportView(visitRecomField);

        statusField.setFont(new java.awt.Font("Tahoma", 0, 14));
        statusField.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Отличное", "Хорошое", "Удовл.", "Плохое", "Смерть" }));
        statusField.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                statusFieldItemStateChanged(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel6.setText(Dictionary.STATUS+":");

        visitOtherPriceField.setFont(new java.awt.Font("Tahoma", 0, 14));
        visitOtherPriceField.setText("0");
        visitOtherPriceField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                visitOtherPriceFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                visitOtherPriceFieldFocusLost(evt);
            }
        });
        visitOtherPriceField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                visitOtherPriceFieldKeyReleased(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel8.setText(Dictionary.OTHER_PRICE+":");

        visitPricePayedField.setFont(new java.awt.Font("Tahoma", 0, 14));
        visitPricePayedField.setText("0");
        visitPricePayedField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                visitPricePayedFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                visitPricePayedFieldFocusLost(evt);
            }
        });
        visitPricePayedField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                visitPricePayedFieldKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                visitPricePayedFieldKeyReleased(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel9.setText(Dictionary.VISIT_PAYED+":");

        visitOtherPricePayedField.setFont(new java.awt.Font("Tahoma", 0, 14));
        visitOtherPricePayedField.setText("0");
        visitOtherPricePayedField.setNextFocusableComponent(visitTabs);
        visitOtherPricePayedField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                visitOtherPricePayedFieldKeyReleased(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel10.setText(Dictionary.PAYED+":");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel12.setText("Дата смерти:");

        dogDeathDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd.MM.yyyy"))));
        dogDeathDate.setFont(new java.awt.Font("Tahoma", 0, 14));
        dogDeathDate.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                dogDeathDateFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                dogDeathDateFocusLost(evt);
            }
        });

        javax.swing.GroupLayout deathDatePanelLayout = new javax.swing.GroupLayout(deathDatePanel);
        deathDatePanel.setLayout(deathDatePanelLayout);
        deathDatePanelLayout.setHorizontalGroup(
            deathDatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, deathDatePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(dogDeathDate, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        deathDatePanelLayout.setVerticalGroup(
            deathDatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deathDatePanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(deathDatePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(dogDeathDate, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12))
                .addContainerGap())
        );

        payedByCard.setFont(new java.awt.Font("Tahoma", 1, 14));
        payedByCard.setText(Dictionary.CARD_PAYMENT+"(Ctrl+k)");
        payedByCard.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(statusField, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(130, 130, 130)
                        .addComponent(deathDatePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(280, 280, 280)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(visitPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(payedByCard, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(visitPricePayedField, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(280, 280, 280)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(visitOtherPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(280, 280, 280)
                        .addComponent(visitOtherPricePayedField, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE))))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addGap(3, 3, 3)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE))
                .addGap(10, 10, 10)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(statusField, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(deathDatePanel, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel9))
                .addGap(3, 3, 3)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(visitPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(payedByCard)
                    .addComponent(visitPricePayedField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel10))
                .addGap(3, 3, 3)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(visitOtherPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(visitOtherPricePayedField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39))
        );

        deathDatePanel.setVisible(false);

        visitTabs.addTab(Dictionary.VISIT+"(F2)", jPanel5);

        diagTable.setFont(new java.awt.Font("Tahoma", 1, 13));
        diagTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                Dictionary.NAMING,
                Dictionary.FINAL,
                Dictionary.DESCR
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Boolean.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        diagTable.setNextFocusableComponent(visitTabs);
        diagTable.setRowHeight(26);
        jScrollPane4.setViewportView(diagTable);
        diagTable.getColumnModel().getColumn(1).setPreferredWidth(100);
        diagTable.getColumnModel().getColumn(1).setMaxWidth(100);
        diagTable.getColumnModel().getColumn(2).setMinWidth(100);
        diagTable.getColumnModel().getColumn(2).setPreferredWidth(100);

        delDiag.setFont(new java.awt.Font("Tahoma", 1, 13));
        delDiag.setText("Удалить");
        delDiag.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delDiagActionPerformed(evt);
            }
        });

        diagBox.setFont(new java.awt.Font("Tahoma", 0, 14));
        diagBox.setText("Введите название диагноза");
        diagBox.setName("diagBox"); // NOI18N
        diagBox.setNextFocusableComponent(diagTable);
        diagBox.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                diagBoxMouseClicked(evt);
            }
        });
        diagBox.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                diagBoxFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                diagBoxFocusLost(evt);
            }
        });
        diagBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                diagBoxKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                diagBoxKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(delDiag)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
                    .addComponent(diagBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(diagBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                .addGap(1, 1, 1)
                .addComponent(delDiag))
        );

        visitTabs.addTab(Dictionary.DIAGNOSE+"(F3)", jPanel1);

        drugTable.setAutoCreateRowSorter(true);
        drugTable.setFont(new java.awt.Font("Tahoma", 1, 13));
        drugTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
            },
            new String [] {
                Dictionary.NAMING,
                Dictionary.PRICE,
                Dictionary.PAYED,
                Dictionary.AMOUNT_SHORT
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class,
                java.lang.Double.class,java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true,true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
            public void setValueAt(Object value, int row, int column) {
                Drug dr = (Drug)super.getValueAt(row, 0);
                if(drugTable.getCellRenderer(row, column) instanceof
                    DrugPriceRenderer)
                {
                    double cena = Double.parseDouble(value.toString())*
                    Double.parseDouble(super.getValueAt(row,3).toString());
                    cena = Dogy.roundPrice(cena);
                    super.setValueAt(value, row, column);
                    DrugPriceRenderer dpr =
                    (DrugPriceRenderer)drugTable.getCellRenderer(row, column);
                    dpr.setSelected(value,row);
                    //Drug dr = (Drug)super.getValueAt(row, 0);
                    dr.setSellPrice(Double.parseDouble(value.toString()));

                    super.setValueAt(cena, row, 2);
                    calculateTotal();
                }else
                {
                    Object oldVal = super.getValueAt(row,column);
                    super.setValueAt(value, row, column);

                    double cena = Double.parseDouble(super.getValueAt(row,1).toString())*
                    Double.parseDouble(super.getValueAt(row,3).toString());
                    cena = Dogy.roundPrice(cena);
                    if(this.getColumnName(column).equals(Dictionary.AMOUNT_SHORT))
                    {
                        if(dr.getMaxAmount() >= (Double)super.getValueAt(row,3))
                        super.setValueAt(cena, row, 2);
                        else
                        {
                            super.setValueAt(oldVal, row, column);
                            mainFrame.FormException(visitTabs,
                                "Такого кол-во на складе нет. Макс - "+dr.getMaxAmount());
                        }
                    }
                    calculateTotal();
                }
            }
        });
        drugTable.setRowHeight(26);
        drugTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                drugTableMouseClicked(evt);
            }
        });
        ArrayList<ArrayList> rows = new ArrayList<ArrayList>();

        drugTable.getColumnModel().getColumn(1).setCellRenderer(
            new DrugPriceRenderer(rows)
        );
        drugTable.getColumnModel().getColumn(1).setCellEditor(
            new DrugPriceCellEditor(rows)
        );
        drugTable.getColumnModel().getColumn(0).setCellRenderer(
            new CellRenderer());
        jScrollPane5.setViewportView(drugTable);

        nameBox.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        nameBox.setText("Введите название предмета или лекарства");
        nameBox.setName("nameBox"); // NOI18N
        nameBox.setNextFocusableComponent(drugTable);
        nameBox.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                nameBoxMouseClicked(evt);
            }
        });
        nameBox.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                nameBoxFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                nameBoxFocusLost(evt);
            }
        });
        nameBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                nameBoxKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                nameBoxKeyReleased(evt);
            }
        });

        typeBox.setFont(new java.awt.Font("Tahoma", 0, 14));
        typeBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Все лек.", "Другое", "Добавить тип" }));
        typeBox.setToolTipText("Искать по типу");
        typeBox.setAutoscrolls(true);
        typeBox.setRequestFocusEnabled(false);
        typeBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                typeBoxItemStateChanged(evt);
            }
        });

        delItem.setFont(new java.awt.Font("Tahoma", 1, 13));
        delItem.setText("Удалить");
        delItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delItemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(delItem)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(nameBox, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
                        .addGap(10, 10, 10)
                        .addComponent(typeBox, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(typeBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(nameBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
                .addGap(1, 1, 1)
                .addComponent(delItem))
        );

        visitTabs.addTab(Dictionary.DRUGS_ITEMS+"(F4)", jPanel2);

        operTable.setFont(new java.awt.Font("Tahoma", 1, 13));
        operTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                Dictionary.NAMING,
                Dictionary.PRICE,
                Dictionary.PAYED,
                Dictionary.COMMENTS
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Double.class, java.lang.Double.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
            public void setValueAt(Object value, int row, int column)
            {
                if(column == 1)
                {
                    double cena = Double.parseDouble(value.toString());
                    super.setValueAt(value,row,column);
                    super.setValueAt(cena,row,2);
                }else
                super.setValueAt(value, row, column);

                calculateTotal();
            }
        });
        operTable.setRowHeight(26);
        jScrollPane6.setViewportView(operTable);
        operTable.getColumnModel().getColumn(1).setMaxWidth(80);
        operTable.getColumnModel().getColumn(2).setMaxWidth(80);
        operTable.getColumnModel().getColumn(3).setMinWidth(100);
        operTable.getColumnModel().getColumn(3).setPreferredWidth(100);

        delOper.setFont(new java.awt.Font("Tahoma", 1, 13));
        delOper.setText(Dictionary.DELETE);
        delOper.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                delOperActionPerformed(evt);
            }
        });

        operBox.setFont(new java.awt.Font("Tahoma", 0, 14));
        operBox.setText("Введите название операции");
        operBox.setName("operBox"); // NOI18N
        operBox.setNextFocusableComponent(operTable);
        operBox.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                operBoxMouseClicked(evt);
            }
        });
        operBox.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                operBoxFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                operBoxFocusLost(evt);
            }
        });
        operBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                operBoxKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                operBoxKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(delOper)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
                    .addComponent(operBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(operBox, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                .addGap(3, 3, 3)
                .addComponent(delOper))
        );

        visitTabs.addTab(Dictionary.OPERATIONS+"(F5)", jPanel3);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setText(Dictionary.TOTAL_PAYED+":");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel2.setText(Dictionary.TOTAL_PRICE);

        totalPriceField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        totalPriceField.setEditable(false);
        totalPriceField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        totalPriceField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        totalPriceField.setText("0.0");
        totalPriceField.setFont(new java.awt.Font("Tahoma", 1, 14));

        totalPayedField.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        totalPayedField.setEditable(false);
        totalPayedField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        totalPayedField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        totalPayedField.setText("0.0");
        totalPayedField.setFont(new java.awt.Font("Tahoma", 1, 14));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel11.setText(Dictionary.DOCTOR+":");

        docField.setFont(new java.awt.Font("Tahoma", 1, 12));

        visitDateField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd.MM.yyyy"))));
        visitDateField.setFont(new java.awt.Font("Tahoma", 1, 14));
        visitDateField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                visitDateFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                visitDateFieldFocusLost(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel7.setText(Dictionary.VISIT_DATE+":");

        currencyComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "EEK", "EUR" }));

        currencyLabel.setFont(new java.awt.Font("Tahoma", 1, 14));
        currencyLabel.setText("Валюта");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(visitTabs, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(totalPriceField)
                            .addComponent(closeButton, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(currencyLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(currencyComboBox, 0, 78, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(visitDateField)
                            .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(docField, 0, 128, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(totalPayedField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                            .addComponent(addVisit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(visitTabs, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 13, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1)
                    .addComponent(jLabel11)
                    .addComponent(jLabel7)
                    .addComponent(currencyLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(totalPayedField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(docField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(visitDateField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(currencyComboBox, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE)
                    .addComponent(totalPriceField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(addVisit, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {currencyComboBox, docField, totalPayedField, totalPriceField, visitDateField});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addVisitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addVisitActionPerformed

        calculateTotal();
        boolean newHealingSet = false;
        try
        {
            if (MainFrame.confirmForm(this, "Сохранить визит ?") == true)
            {
                Database.beginTransaction();
                if(healingSet == null)
                    newHealingSet=true;

                if (visit == null && !toChange) {
                    System.out.println("newVisit");
                    addNewVisit();
                } else {
                    System.out.println("changeVisit");
                    changeVisit();
                }
                Database.endTransaction();
                Database.enableAutoCommit();
                
                this.dispose();
            }
        }catch(SQLException e)
        {
            try
            {
              Database.rollBack();
            }catch(SQLException ex)
            { mainFrame.SQLException(ex); }

            mainFrame.SQLException(e);
        } 
        catch (ParseException ex) {
                mainFrame.Exception(ex);
        }
        catch (FormException fe) {
                mainFrame.FormException(this, fe.getMessage());
        }finally
        {
            System.out.println("final");
            //parentWindow.setActiveVisit();
            if(newHealingSet)
                  healingSet = null;
            try
            {
              Database.enableAutoCommit();
            } catch(Exception e)
            {  mainFrame.Exception(e);  }
        }

}//GEN-LAST:event_addVisitActionPerformed

    private void changeVisit() throws SQLException, ParseException {
        int healId = 0;
        
        SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
        Date visDate = null;
        int visitId = 0;
        int docId = ((Doctor)docField.getSelectedItem()).getId();
        ArrayList toDelete = new ArrayList();
                visDate = new Date(formatter.parse(visitDateField.getText()).getTime());
                healId = healingSet.getId();
                healingSet.setLastVisit(visDate);
                if (!this.healingResultIsEmpty()) {
                    healingSet.setResult(healingResultField.getText());
                }
                Healings.updateHealing(healId, healingSet);
                //Visit
                Visits.changeVisit(
                        visitInfo.getId(), selDog.getId(), docId, visDate,
                        Double.parseDouble(visitPriceField.getText()),
                        Double.parseDouble(visitOtherPriceField.getText()),
                        Double.parseDouble(visitPricePayedField.getText()),
                        Double.parseDouble(visitOtherPriceField.getText()),
                        payedByCard.isSelected(),
                        currencyComboBox.getSelectedItem().toString(),
                        visitDescrField.getText(), visitRecomField.getText(),
                        statusField.getSelectedItem().toString(),
                        healId);
                visitId = visitInfo.getId();
                
                //Diags
                toDelete.clear();
                for (int i = 0; i < diagTable.getRowCount(); i++) {
                    if (diagTable.getValueAt(i, 0) instanceof Diagnose) {
                        Diagnose diag = (Diagnose) diagTable.getValueAt(i, 0);
                        boolean okon = (Boolean) diagTable.getValueAt(i, 1);
                        String descr = (String) diagTable.getValueAt(i, 2);
                        if (!visitDiags.contains(diag)) {
                            // add new diag
                            Diagnoses.addDiagnose(diag.getId(), docId, descr, visDate,
                                    0, 0, visitId, selDog.getId(), okon);
                            //
                        } else {
                            Diagnoses.updateDiagnose(
                                    diag.getDisID(),
                                    visitInfo.getId(), diag.getId(),
                                    docId, descr, visDate,
                                    0, 0, selDog.getId(),
                                    okon, diag.isDeleted());
                            toDelete.add(diag);
                        }
                    }
                }
                 for(int i=0; i<toDelete.size(); i++)
                    visitDiags.remove(toDelete.get(i));
                
                // remove deleted
                for (int i = 0; i < visitDiags.size(); i++) {
                    Diagnose diag = (Diagnose) visitDiags.get(i);
                    diag.setDeleted(true);
                    Diagnoses.updateDiagnose(
                            diag.getDisID(),
                            visitInfo.getId(), diag.getId(),
                            docId, diag.getDescr(), visDate,
                            0, 0, selDog.getId(),
                            !diag.isPredv(), diag.isDeleted());
                }
               

                //Opers
                toDelete.clear();
                for (int i = 0; i < operTable.getRowCount(); i++) {
                    if (operTable.getValueAt(i, 0) instanceof Operation) {
                        Operation oper = (Operation) operTable.getValueAt(i, 0);
                        double sellPrice = Double.parseDouble(operTable.getValueAt(i, 1).toString());
                        double payed = Double.parseDouble(operTable.getValueAt(i, 2).toString());
                        String descr = operTable.getValueAt(i, 3).toString();
                        if (!visitOpers.contains(oper))
                        {
                            Operations.addOperation(oper.getId(), sellPrice,
                                    payed, visDate,
                                    descr, visitId,
                                    selDog.getId(), docId);
                        } else {
                            Operations.updateOperation(
                                    oper.getDisID(),
                                    visitInfo.getId(), oper.getId(),
                                    sellPrice, payed, visDate,
                                    descr, selDog.getId(),
                                    docId, oper.isDeleted());
                            toDelete.add(oper);
                        }
                    }
                }
                for(int i=0; i<toDelete.size(); i++)
                    visitOpers.remove(toDelete.get(i));

                // remove opers
                for (int i = 0; i < visitOpers.size(); i++) {
                    Operation oper = (Operation) visitOpers.get(i);
                    oper.setDeleted(true);
                    Operations.updateOperation(
                            oper.getDisID(),
                            visitInfo.getId(), oper.getId(),
                            oper.getSellPrice(),
                            oper.getPayed(),
                            visDate,
                            oper.getDescr(), selDog.getId(),
                            docId, oper.isDeleted());
                }

                //Drugs
                toDelete.clear();
                for (int i = 0; i < drugTable.getRowCount(); i++) {
                    if (drugTable.getValueAt(i, 0) instanceof Drug) {
                        Drug dr = (Drug) drugTable.getValueAt(i, 0);
                        double payed = Double.parseDouble(drugTable.getValueAt(i, 2).toString());
                        double amount = Double.parseDouble(drugTable.getValueAt(i, 3).toString());
                        if (!visitDrugs.contains(dr))
                        {
                            System.out.println("disDrug");
                            Drugs.addDrug(visitId, dr.getRecId(),
                                    selDog.getId(), docId,
                                    dr.getSellPrice()*amount, visDate, "", payed, amount);

                        }// TODO descr
                        else
                        {
                            System.out.println("updateDrug");
                            int res = Drugs.updateDisDrug(
                                    dr.getDisID(),
                                    visitId, dr.getRecId(),
                                    selDog.getId(), docId,
                                    dr.getSellPrice()*amount, visDate,
                                    "", payed, amount, dr.getAmount(),
                                    dr.isDeleted());
                            toDelete.add(dr);
                        }
                    }
                }
                
                for(int i=0; i<toDelete.size(); i++)
                    visitDrugs.remove(toDelete.get(i));

                for (int i = 0; i < visitDrugs.size(); i++) {
                    Drug dr = (Drug) visitDrugs.get(i);
                    dr.setDeleted(true);
                    Drugs.updateDisDrug(
                            dr.getDisID(),
                            visitId, dr.getRecId(),
                            selDog.getId(), docId,
                            0, visDate,
                            "", 0,
                            0, dr.getAmount(), dr.isDeleted());
                }
                //if(MainFrame.okForm(this, "Визит изменен"));
                if(!dogDeathDate.getText().isEmpty())
                {
                    visDate = new Date(formatter.parse(dogDeathDate.getText()).getTime());
                    Dogs.killDog(selDog.getId(), visDate);
                    parentWindow.fillDogTable(user.getDogs(),selDog.getId());
                }
                parentWindow.resetValues(visitId);
                //this.dispose();
           
    }

    private void addNewVisit() throws SQLException, FormException, ParseException {
        int healId = 0;
        SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
        Date visDate = null;
        int visitId = 0;
        int docId = ((Doctor)docField.getSelectedItem()).getId();
        boolean newHealingSet = false;
                visDate = new Date(formatter.parse(visitDateField.getText()).getTime());

                //HealingSet
                //TODO
                if (healingSet == null) {

                    HealingSet healingSet = new HealingSet();
                    healingSet.setFirstVisit(visDate);
                    healingSet.setLastVisit(visDate);
                    if (!healingNameIsEmpty()) {
                        healingSet.setName(healingNameField.getText());
                    } else {
                        healingSet = null;
                        throw new FormException("Укажите имя курса");
                    }
                    if (!this.healingResultIsEmpty()) {
                        healingSet.setResult(healingResultField.getText());
                    }
                    healId = Healings.addHealing(selDog.getId(),
                            healingSet.getName(),
                            healingSet.getResult(),
                            visDate, visDate);
                    newHealingSet = true;
                } else {
                    healId = healingSet.getId();
                    healingSet.setLastVisit(visDate);
                    if (!this.healingResultIsEmpty()) {
                        healingSet.setResult(healingResultField.getText());
                    }
                    Healings.updateHealing(healId, healingSet);
                }

                //Visit
                visitId = Visits.addVisit(selDog.getId(), docId, visDate,
                        Double.parseDouble(visitPriceField.getText()),
                        Double.parseDouble(visitOtherPriceField.getText()),
                        Double.parseDouble(visitPricePayedField.getText()),
                        Double.parseDouble(visitOtherPricePayedField.getText()),
                        payedByCard.isSelected(),
                        currencyComboBox.getSelectedItem().toString(),
                        visitDescrField.getText(), visitRecomField.getText(),
                        statusField.getSelectedItem().toString(),
                        healId);
                //Diags
                for (int i = 0; i < diagTable.getRowCount(); i++) {
                    if (diagTable.getValueAt(i, 0) instanceof Diagnose) {
                        Diagnose diag = (Diagnose) diagTable.getValueAt(i, 0);
                        boolean okon = (Boolean) diagTable.getValueAt(i, 1);
                        String descr = (String) diagTable.getValueAt(i, 2);
                        Diagnoses.addDiagnose(diag.getId(), docId, descr, visDate,
                                0, 0, visitId, selDog.getId(), okon);
                    }
                }

                //Opers
                for (int i = 0; i < operTable.getRowCount(); i++) {
                    if (operTable.getValueAt(i, 0) instanceof Operation) {
                        Operation oper = (Operation) operTable.getValueAt(i, 0);
                        double sellPrice = Double.parseDouble(operTable.getValueAt(i, 1).toString());
                        double payed = Double.parseDouble(operTable.getValueAt(i, 2).toString());
                        String descr = operTable.getValueAt(i, 3).toString();
                        //TODO
                        Operations.addOperation(oper.getId(), sellPrice, payed, visDate,
                                descr, visitId, selDog.getId(), docId);
                    }
                }

                //Drugs
                for (int i = 0; i < drugTable.getRowCount(); i++) {
                    if (drugTable.getValueAt(i, 0) instanceof Drug) {
                        Drug dr = (Drug) drugTable.getValueAt(i, 0);
                        double payed = Double.parseDouble(drugTable.getValueAt(i, 2).toString());
                        double amount = Double.parseDouble(drugTable.getValueAt(i, 3).toString());
                        //TODO
                        Drugs.addDrug(visitId, dr.getRecId(), selDog.getId(), docId,
                                dr.getSellPrice()*amount, visDate, "", payed, amount);
                    }
                }
                if(!dogDeathDate.getText().isEmpty())
                {
                    visDate = new Date(formatter.parse(dogDeathDate.getText()).getTime());
                    Dogs.killDog(selDog.getId(), visDate);
                    parentWindow.fillDogTable(user.getDogs(),selDog.getId());
                }
                //if(MainFrame.okForm(this, "Визит записан"));
                parentWindow.resetValues(visitId);
                //this.dispose();
            
    }

    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
        dialog.setVisible(false);
        this.dispose();
}//GEN-LAST:event_closeButtonActionPerformed

    private void drugTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_drugTableMouseClicked
}//GEN-LAST:event_drugTableMouseClicked

    private void nameBoxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nameBoxMouseClicked
        activeField = nameBox;
        if (nameBox.getText().equals("")) {
            nameBoxKeyReleased(null);
        }
}//GEN-LAST:event_nameBoxMouseClicked

    private void nameBoxFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameBoxFocusGained
        Dogy.focusGained(nameBox, nameText);
        if (nameBoxIsEmpty())
            nameBoxKeyReleased(null);
    }//GEN-LAST:event_nameBoxFocusGained

    private void nameBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameBoxFocusLost
        boxPopup.setVisible(false);
        Dogy.focusLost(nameBox, nameText);
        if (nameBoxIsEmpty()) {
            choosenItem = null;
        }
}//GEN-LAST:event_nameBoxFocusLost

    private void nameBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nameBoxKeyPressed
        /*if (evt.getKeyCode() == evt.VK_DOWN) {
            if (list.getSelectedIndex() == -1) {
                list.setSelectedIndex(0);
            } else {
                list.setSelectedIndex(list.getSelectedIndex() + 1);
                int vR = (list.getLastVisibleIndex() - list.getFirstVisibleIndex()) / 2;
                list.ensureIndexIsVisible(list.getSelectedIndex() + vR);
            }
        }
        if (evt.getKeyCode() == evt.VK_UP) {
            if (list.getSelectedIndex() > 0) {
                list.setSelectedIndex(list.getSelectedIndex() - 1);
                int vR = (list.getLastVisibleIndex() - list.getFirstVisibleIndex()) / 2;
                int vis = list.getSelectedIndex() - vR;
                if (vis < 0) {
                    vis = 0;
                }
                list.ensureIndexIsVisible(vis);
            }
        }*/
        Dogy.listScroll(list, evt);
}//GEN-LAST:event_nameBoxKeyPressed

    private void nameBoxKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nameBoxKeyReleased
        activeField = nameBox;
        if (evt != null && evt.getKeyCode() == KeyEvent.VK_ENTER) {
            //boxPopup.setVisible(false);
            
            if (list.getSelectedIndex() != -1) {
                listMouseClicked(null);
            }
            
        } else if (evt != null && evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            boxPopup.setVisible(false);
        } else if (!dialog.isVisible() && (evt == null || !evt.isActionKey())) {
            try {
                ArrayList choices = null;
                list.ensureIndexIsVisible(0);
                if (typeBox.getSelectedIndex() == 0)
                {
                    choices = Sklad_drugs.getAvailDrugNames(nameBox.getText());
                    choices.addAll(Sklad_drugs.getAvailDrugNamesWithType(nameBox.getText(), "muud"));
                //choices= Sklad_drugs.getByName(nameBox.getText());
                //choices.addAll(Sklad_drugs.getByNameAndType(nameBox.getText(),"muud"));
                } else if (typeBox.getSelectedIndex() == 1) {
                    choices = Sklad_drugs.getAvailDrugNames(nameBox.getText());
                //choices= Sklad_drugs.getByName(nameBox.getText());
                } else if (typeBox.getSelectedItem().toString().equals(Dictionary.OTHER)) {
                    choices = Sklad_drugs.getAvailDrugNamesWithType(nameBox.getText(), "muud");
                //choices = Sklad_drugs.getByNameAndType(nameBox.getText(),"muud");
                } else {
                    choices = Sklad_drugs.getAvailDrugNamesWithType(nameBox.getText(), typeBox.getSelectedItem().toString());
                //choices= Sklad_drugs.getByNameAndType(nameBox.getText(),typeBox.getSelectedItem().toString());
                }

                list.setListData(choices.toArray());
                try {
                    boxPopup.setLocation(nameBox.getLocationOnScreen().x,
                            nameBox.getLocationOnScreen().y + nameBox.getHeight());
                    //boxPopup.setBounds(nameBox.getLocationOnScreen().x,
                    //        nameBox.getLocationOnScreen().y + nameBox.getHeight(),
                    //        nameBox.getWidth(), boxPopup.getHeight());
                    list.repaint();
                    boxPopup.repaint();
                    boxPopup.setVisible(true);
                } catch (Exception e) {
                }


            } catch (SQLException ex) {
                mainFrame.SQLException(ex);
            }
        }
}//GEN-LAST:event_nameBoxKeyReleased

    private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
        //boxPopup.setVisible(false);
        if ((list.getSelectedValue() != null &&
                list.getSelectedValue().toString().equals(Dictionary.ADD_NEW) ||
                list.getSelectedIndex() == 0 ||
                (list.getSelectedIndex() == -1 && list.getModel().getSize() == 1)) && !activeField.getName().equals("nameBox")) {
            showAddWindow();
        } else {
            if (activeField != null) {

                // drugs and items
                if (activeField.getName().equals("nameBox")) {
                    if (list.getSelectedValue() instanceof Item ) {
                        DefaultTableModel model = (DefaultTableModel) drugTable.getModel();
                        Item item = null;
                        if (list.getModel().getSize() == 1) {
                            item = (Item) list.getModel().getElementAt(0);
                        } else {
                            item = (Item) list.getSelectedValue();
                        }
                        if (item != null)
                        {
                            if(!findDrugDubl((Drug)item) )
                            model.addRow(new Object[]{(Item) list.getSelectedValue(),
                                        item.getSellPrices()[1], 0, 0.0
                                    });
                            else
                                mainFrame.FormException(this, "Такое лекарство уже добавлено.");

                            drugTable.requestFocus();
                            drugTable.setRowSelectionInterval(drugTable.getRowCount()-1, drugTable.getRowCount()-1);
                            
                            drugTable.editCellAt(drugTable.getRowCount()-1, 3);
                            drugTable.getCellEditor(
                                 drugTable.getRowCount()-1, 3).
                            getTableCellEditorComponent(drugTable, drugTable.getValueAt(drugTable.getRowCount()-1, 3),
                            true, drugTable.getRowCount()-1, 3).requestFocus();
                        }
                        drugTable.setModel(model);
                        activeField.setText("");
                        boxPopup.setVisible(false);
                    }else
                    if (list.getSelectedValue() instanceof String) {
                        ArrayList choices = null;
                        list.ensureIndexIsVisible(0);
                        try {
                            choices =
                                    Sklad_drugs.getByStrictName((String) list.getSelectedValue());

                            Object obj = new Object()
                            {
                                private String str = (String)list.getSelectedValue();
                                public String toString()
                                {
                                  return "<html><b>"+str+"</b></html>";
                                }
                            };
                            choices.add(0,obj);
                            list.setListData(choices.toArray());
                            boxPopup.setVisible(true);
                            boxPopup.requestFocus();
                        } catch (SQLException ex) {
                            mainFrame.SQLException(ex);
                        }
                    }else
                        return;

                }
                if (activeField.getName().equals("diagBox")) {
                    this.addToDiagTable((Diagnose) list.getSelectedValue(), false);
                    activeField.setText("");
                    boxPopup.setVisible(false);
                }
                if (activeField.getName().equals("operBox")) {
                    DefaultTableModel model = (DefaultTableModel) operTable.getModel();
                    Operation oper = (Operation) list.getSelectedValue();
                    model.addRow(new Object[]{oper, 0.0, 0.0, ""});
                    operTable.requestFocus();
                    operTable.setRowSelectionInterval(operTable.getRowCount()-1, operTable.getRowCount()-1);

                    operTable.editCellAt(operTable.getRowCount()-1, 1);
                    operTable.getCellEditor(
                    operTable.getRowCount()-1, 1).
                      getTableCellEditorComponent(operTable, operTable.getValueAt(operTable.getRowCount()-1, 1),
                      true, operTable.getRowCount()-1, 1).requestFocus();
                    operTable.setModel(model);
                    activeField.setText("");
                    boxPopup.setVisible(false);
                }

            }
        }
    }//GEN-LAST:event_listMouseClicked

    private void typeBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_typeBoxItemStateChanged
        nameBoxKeyReleased(null);
        list.setSelectedIndex(list.getFirstVisibleIndex() + 1);
}//GEN-LAST:event_typeBoxItemStateChanged

    private void delItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delItemActionPerformed
        int[] sel = drugTable.getSelectedRows();
        Arrays.sort(sel);
        DefaultTableModel model = (DefaultTableModel) drugTable.getModel();
        for (int i = 0; i < sel.length; i++) {
            model.setValueAt(0.0, sel[i] - i, 3);
            model.removeRow(sel[i] - i);
        }
        drugTable.setModel(model);
        calculateTotal();
}//GEN-LAST:event_delItemActionPerformed

    private void delOperActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delOperActionPerformed
        int[] sel = operTable.getSelectedRows();
        Arrays.sort(sel);
        DefaultTableModel model = (DefaultTableModel) operTable.getModel();
        for (int i = 0; i < sel.length; i++) {
            model.removeRow(sel[i] - i);
        }
        operTable.setModel(model);
        calculateTotal();
}//GEN-LAST:event_delOperActionPerformed

    private void delDiagActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delDiagActionPerformed
        int[] sel = diagTable.getSelectedRows();
        Arrays.sort(sel);
        DefaultTableModel model = (DefaultTableModel) diagTable.getModel();
        for (int i = 0; i < sel.length; i++) {
            press.put(model.getValueAt(sel[i] - i, 0).toString(), false);
            model.removeRow(sel[i] - i);
        }
        diagTable.setModel(model);

}//GEN-LAST:event_delDiagActionPerformed

    private void diagBoxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_diagBoxMouseClicked
        activeField = diagBox;
        if (diagBox.getText().equals("")) {
            diagBoxKeyReleased(null);
        }
}//GEN-LAST:event_diagBoxMouseClicked

    private void diagBoxFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_diagBoxFocusGained
        Dogy.focusGained(diagBox, "Введите название диагноза");
        if (diagBoxIsEmpty())
            diagBoxKeyReleased(null);
}//GEN-LAST:event_diagBoxFocusGained

    private void diagBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_diagBoxFocusLost
        boxPopup.setVisible(false);
        Dogy.focusLost(diagBox, "Введите название диагноза");
        if (diagBoxIsEmpty()) {
            choosenDiag = null;
        }
}//GEN-LAST:event_diagBoxFocusLost

    private void diagBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_diagBoxKeyPressed
        /*if (evt.getKeyCode() == evt.VK_DOWN) {
            if (list.getSelectedIndex() == -1) {
                list.setSelectedIndex(0);
            } else {
                list.setSelectedIndex(list.getSelectedIndex() + 1);
                int vR = (list.getLastVisibleIndex() - list.getFirstVisibleIndex()) / 2;
                list.ensureIndexIsVisible(list.getSelectedIndex() + vR);
            }
        }
        if (evt.getKeyCode() == evt.VK_UP) {
            if (list.getSelectedIndex() > 0) {
                list.setSelectedIndex(list.getSelectedIndex() - 1);
                int vR = (list.getLastVisibleIndex() - list.getFirstVisibleIndex()) / 2;
                int vis = list.getSelectedIndex() - vR;
                if (vis < 0) {
                    vis = 0;
                }
                list.ensureIndexIsVisible(vis);
            }
        }*/
        Dogy.listScroll(list, evt);
        if (evt.getKeyCode() == evt.VK_TAB)
            diagTable.requestFocus();
}//GEN-LAST:event_diagBoxKeyPressed

    private void diagBoxKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_diagBoxKeyReleased
        activeField = diagBox;
        
        if (evt != null && evt.getKeyCode() == KeyEvent.VK_ENTER) {
            boxPopup.setVisible(false);
            
            if (!diagBox.getText().equals("") || list.getSelectedIndex() > 0) {
                listMouseClicked(null);
            } else {
                showAddWindow();
            }

        } else if (evt != null && evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            boxPopup.setVisible(false);
        } else if (!dialog.isVisible() && (evt == null || !evt.isActionKey())) {
            try {
                list.ensureIndexIsVisible(0);
                ArrayList choices = null;
                choices = Diagnoses.getByName(diagBox.getText());


                choices.add(0, "<html><b>"+Dictionary.ADD_NEW+"</b>");


                list.setListData(choices.toArray());
                try {
                    boxPopup.setLocation(diagBox.getLocationOnScreen().x,
                            diagBox.getLocationOnScreen().y + diagBox.getHeight());
                    list.repaint();
                    boxPopup.repaint();
                    boxPopup.setVisible(true);
                } catch (Exception e) {
                }


            } catch (SQLException ex) {
                mainFrame.SQLException(ex);
            }
        }
}//GEN-LAST:event_diagBoxKeyReleased

    private void operBoxMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_operBoxMouseClicked
        activeField = operBox;
        if (operBox.getText().equals("")) {
            operBoxKeyReleased(null);
        }
}//GEN-LAST:event_operBoxMouseClicked

    private void operBoxFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_operBoxFocusGained
        Dogy.focusGained(operBox, operText);
        if (operBoxIsEmpty())
            operBoxKeyReleased(null);
}//GEN-LAST:event_operBoxFocusGained

    private void operBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_operBoxFocusLost
        boxPopup.setVisible(false);
        Dogy.focusLost(operBox, operText);
        if (operBoxIsEmpty()) {
            choosenOper = null;
        }
}//GEN-LAST:event_operBoxFocusLost

    private void operBoxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_operBoxKeyPressed
        /*if (evt.getKeyCode() == evt.VK_DOWN) {
            if (list.getSelectedIndex() == -1) {
                list.setSelectedIndex(0);
            } else {
                list.setSelectedIndex(list.getSelectedIndex() + 1);
                int vR = (list.getLastVisibleIndex() - list.getFirstVisibleIndex()) / 2;
                list.ensureIndexIsVisible(list.getSelectedIndex() + vR);
            }
        }
        if (evt.getKeyCode() == evt.VK_UP) {
            if (list.getSelectedIndex() > 0) {
                list.setSelectedIndex(list.getSelectedIndex() - 1);
                int vR = (list.getLastVisibleIndex() - list.getFirstVisibleIndex()) / 2;
                int vis = list.getSelectedIndex() - vR;
                if (vis < 0) {
                    vis = 0;
                }
                list.ensureIndexIsVisible(vis);
            }
        }*/
        Dogy.listScroll(list, evt);
}//GEN-LAST:event_operBoxKeyPressed

    private void operBoxKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_operBoxKeyReleased
        activeField = operBox;
        if (evt != null && evt.getKeyCode() == KeyEvent.VK_ENTER) {
            boxPopup.setVisible(false);
            
            if (!operBox.getText().equals("") || list.getSelectedIndex() > 0) {
                listMouseClicked(null);
            } else {
                showAddWindow();
            }

        } else if (evt != null && evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
            boxPopup.setVisible(false);
        } else if (!dialog.isVisible() && (evt == null || !evt.isActionKey())) {
            try {
                list.ensureIndexIsVisible(0);
                ArrayList choices = null;
                choices = Operations.getByName(operBox.getText());


                choices.add(0, "<html><b>"+Dictionary.ADD_NEW+"</b>");


                list.setListData(choices.toArray());
                try {
                    boxPopup.setLocation(operBox.getLocationOnScreen().x,
                            operBox.getLocationOnScreen().y + operBox.getHeight());
                    list.repaint();
                boxPopup.repaint();
                    boxPopup.setVisible(true);
                } catch (Exception e) {
                }


            } catch (SQLException ex) {
                mainFrame.SQLException(ex);
            }
        }
}//GEN-LAST:event_operBoxKeyReleased

    private void formWindowGainedFocus(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowGainedFocus
        if (dialog.isVisible()) {
            dialog.requestFocus();
        }
    }//GEN-LAST:event_formWindowGainedFocus

    private void dialogWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_dialogWindowClosed
        this.setEnabled(true);
        this.requestFocus();
    }//GEN-LAST:event_dialogWindowClosed

    private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved
        if (activeField != null && (dialog.isVisible() || boxPopup.isVisible())) {
            JTextField field = activeField;
            boxPopup.setLocation(field.getLocationOnScreen().x,
                    field.getLocationOnScreen().y + field.getHeight());
            dialog.setLocation(field.getLocationOnScreen().x,
                    field.getLocationOnScreen().y + field.getHeight());
        }
    }//GEN-LAST:event_formComponentMoved

    private void healingResultFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_healingResultFieldFocusGained
        Dogy.focusGained(healingResultField, healingResultText);
    }//GEN-LAST:event_healingResultFieldFocusGained

    private void healingResultFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_healingResultFieldFocusLost
        Dogy.focusLost(healingResultField, healingResultText);
    }//GEN-LAST:event_healingResultFieldFocusLost

    private void visitDateFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitDateFieldFocusGained
        if(visitDateField.getText().isEmpty())
            visitDateField.setText(new FDate(Calendar.getInstance().getTime().getTime())+"");
    }//GEN-LAST:event_visitDateFieldFocusGained

    private void visitDateFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitDateFieldFocusLost
        if(visitDateField.getText().isEmpty())
            visitDateField.setText(new FDate(Calendar.getInstance().getTime().getTime())+"");
    }//GEN-LAST:event_visitDateFieldFocusLost

    private void visitPriceFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitPriceFieldKeyReleased
        visitPricePayedField.setText(visitPriceField.getText());
        calculateTotal();
    }//GEN-LAST:event_visitPriceFieldKeyReleased

    private void visitPriceFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitPriceFieldKeyPressed
    }//GEN-LAST:event_visitPriceFieldKeyPressed

    private void visitPriceFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitPriceFieldFocusLost
        calculateTotal();
    }//GEN-LAST:event_visitPriceFieldFocusLost

    private void visitPriceFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitPriceFieldFocusGained
        calculateTotal();

    }//GEN-LAST:event_visitPriceFieldFocusGained

    private void healingNameFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_healingNameFieldFocusGained
        Dogy.focusGained(healingNameField, healingNameText);
    }//GEN-LAST:event_healingNameFieldFocusGained

    private void healingNameFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_healingNameFieldFocusLost
        Dogy.focusLost(healingNameField, healingNameText);
    }//GEN-LAST:event_healingNameFieldFocusLost

    private void visitPricePayedFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitPricePayedFieldFocusGained
        // TODO add your handling code here:
}//GEN-LAST:event_visitPricePayedFieldFocusGained

    private void visitPricePayedFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitPricePayedFieldFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_visitPricePayedFieldFocusLost

    private void visitPricePayedFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitPricePayedFieldKeyPressed
        // TODO add your handling code here:
}//GEN-LAST:event_visitPricePayedFieldKeyPressed

    private void visitPricePayedFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitPricePayedFieldKeyReleased
        this.calculateTotal();
}//GEN-LAST:event_visitPricePayedFieldKeyReleased

    private void visitOtherPricePayedFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitOtherPricePayedFieldKeyReleased
        this.calculateTotal();
    }//GEN-LAST:event_visitOtherPricePayedFieldKeyReleased

    private void visitOtherPriceFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitOtherPriceFieldKeyReleased
        visitOtherPricePayedField.setText(visitOtherPriceField.getText());
        this.calculateTotal();
    }//GEN-LAST:event_visitOtherPriceFieldKeyReleased

    private void visitOtherPriceFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitOtherPriceFieldFocusGained
        visitOtherPricePayedField.setText(visitOtherPriceField.getText());
        this.calculateTotal();
    }//GEN-LAST:event_visitOtherPriceFieldFocusGained

    private void visitOtherPriceFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_visitOtherPriceFieldFocusLost
        visitOtherPricePayedField.setText(visitOtherPriceField.getText());
        this.calculateTotal();
    }//GEN-LAST:event_visitOtherPriceFieldFocusLost

    private void visitTabsKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitTabsKeyTyped
       
    }//GEN-LAST:event_visitTabsKeyTyped

    private void visitDescrFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitDescrFieldKeyReleased
        
    }//GEN-LAST:event_visitDescrFieldKeyReleased

    private void visitDescrFieldKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitDescrFieldKeyTyped
        
    }//GEN-LAST:event_visitDescrFieldKeyTyped

    private void visitDescrFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_visitDescrFieldKeyPressed
        
    }//GEN-LAST:event_visitDescrFieldKeyPressed

    private void setHealingNameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setHealingNameButtonActionPerformed
        if(diagTable.getRowCount() > 0)
            healingNameField.setText(diagTable.getValueAt(0, 0)+"");
        else
            return;
        for(int i=1; i< diagTable.getRowCount(); i++)
           healingNameField.setText(healingNameField.getText()+
                                                ","+diagTable.getValueAt(i, 0));
        healingNameField.setForeground(Color.black);
}//GEN-LAST:event_setHealingNameButtonActionPerformed

    private void dogDeathDateFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dogDeathDateFocusGained
        // TODO add your handling code here:
}//GEN-LAST:event_dogDeathDateFocusGained

    private void dogDeathDateFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dogDeathDateFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_dogDeathDateFocusLost

    private void statusFieldItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_statusFieldItemStateChanged
        if(statusField.getSelectedIndex() == statusField.getItemCount()-1)
        {
            deathDatePanel.setVisible(true);
            SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
            dogDeathDate.setText(sdf.format(Calendar.getInstance().getTime()));
        }
        else
        {
            deathDatePanel.setVisible(false);
            dogDeathDate.setText("");
        }
    }//GEN-LAST:event_statusFieldItemStateChanged
    private void showAddWindow() {
        if (activeField != null && activeField.getName().equals("diagBox")) {
            dialog.setContentPane(new fastDiagAdd(choosenDiag, this));
        }
        if (activeField != null && activeField.getName().equals("operBox")) {
            dialog.setContentPane(new fastOperAdd(choosenOper, this));
        }

        dialog.pack();
        dialog.setLocation(activeField.getLocationOnScreen().x,
                activeField.getLocationOnScreen().y + activeField.getHeight());
        dialog.setVisible(true);
    }

    public void addToTable(Object obj) {
        activeField.setForeground(Color.black);
        activeField.setText("");
        if (obj instanceof Item || obj instanceof Drug) {
            choosenItem = (Item) obj;
        }
        if (obj instanceof Diagnose) {
            choosenDiag = (Diagnose) obj;
            DefaultTableModel model = (DefaultTableModel) diagTable.getModel();
            Diagnose diag = (Diagnose) obj;
            model.addRow(new Object[]{diag, false, diag.getDescr()});
        }
        if (obj instanceof Operation) {
            choosenOper = (Operation) obj;
            DefaultTableModel model = (DefaultTableModel) operTable.getModel();
            Operation oper = (Operation) obj;
            System.out.println("OperDes: "+oper.getDescr());
            model.addRow(new Object[]{oper, 0, 0,oper.getDescr()});
        }
    }

    public void addToDiagTable(Diagnose diag, boolean okon) {
        DefaultTableModel model = (DefaultTableModel) diagTable.getModel();
        boolean found = false;
        for (int i = 0; i < model.getRowCount(); i++) {
            if (model.getValueAt(i, 0).toString().equals(diag.toString())) {
                found = true;
                break;
            }
        }
        if (!found) {
            //if(okon)
            //    diag.setFinal();
            //else
            //    diag.setPredv();
            model.addRow(new Object[]{diag, okon, diag.getDescr()});
        }
        press.put(diag.toString(), true);
        diagTable.setModel(model);
    }

    public void addToDrugTable(Drug drug) {

        DefaultTableModel model = (DefaultTableModel) drugTable.getModel();
        model.addRow(new Object[]{
                    drug,
                    drug.getSellPrice(), 
                    drug.getPayed(),
                    drug.getAmount()
                });
        drugTable.setModel(model);
    }

    public void addToOperTable(Operation oper) {
        DefaultTableModel model = (DefaultTableModel) operTable.getModel();
        model.addRow(new Object[]{oper, oper.getSellPrice(),
                    oper.getPayed(), oper.getDescr()});
        operTable.setModel(model);
    }

    public void decreaseTotalPrice(double pr) {
        if ((totalPrice - pr) >= 0) {
            totalPrice -= pr;
        } else {
            totalPrice = 0;
        }
        totalPrice = Dogy.roundPrice(totalPrice);
        totalPriceField.setText(totalPrice + "");
        try {
            totalPriceField.commitEdit();
        } catch (ParseException ex) {
            Logger.getLogger(NewVisit.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void increaseTotalPrice(double pr) {
        totalPrice += pr;
        totalPrice = Dogy.roundPrice(totalPrice);
        totalPriceField.setText(totalPrice + "");
        try {
            totalPriceField.commitEdit();
        } catch (ParseException ex) {
            Logger.getLogger(NewVisit.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void disposeDialog() {
        dialog.setVisible(false);
    }

    public Diagnose getChoosenDiag() {
        return choosenDiag;
    }

    public Operation getChoosenOper() {
        return choosenOper;
    }

    public String getActiveFieldText() {
        return activeField.getText();
    }

    private boolean nameBoxIsEmpty() {
        return nameBox.getText().equals("") || nameBox.getText().equals(nameText);
    }

    private boolean healingResultIsEmpty() {
        return healingResultField.getText().equals("") ||
                healingResultField.getText().equals(healingResultText);
    }

    private boolean healingNameIsEmpty() {
        return healingNameField.getText().equals("") ||
                healingNameField.getText().equals(healingNameText);

    }

    private boolean diagBoxIsEmpty() {
        return diagBox.getText().equals("") || diagBox.getText().equals(diagText);
    }

    private boolean operBoxIsEmpty() {
        return operBox.getText().equals("") || operBox.getText().equals(operText);
    }

    public JTextField getActiveField() {
        return activeField;
    }
    public void setParentWindow(UserCard comp)
    {
        parentWindow = comp;
    }
    private boolean findDrugDubl(Drug item)
    {
       DefaultTableModel model = (DefaultTableModel) drugTable.getModel();
       int sklId=0;
       for(int i=0; i< model.getRowCount(); i++ )
       {
           sklId = ((Drug)model.getValueAt(i, 0)).getRecId();
          if(item.getRecId() == ((Drug)model.getValueAt(i, 0)).getRecId() )
              return true;
       }
       return false;
    }

    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addVisit;
    private javax.swing.JScrollPane boxList;
    private javax.swing.JPopupMenu boxPopup;
    private javax.swing.JButton closeButton;
    private javax.swing.JComboBox currencyComboBox;
    private javax.swing.JLabel currencyLabel;
    private javax.swing.JPanel deathDatePanel;
    private javax.swing.JButton delDiag;
    private javax.swing.JButton delItem;
    private javax.swing.JButton delOper;
    private javax.swing.JTextField diagBox;
    private javax.swing.JTable diagTable;
    private javax.swing.JDialog dialog;
    private javax.swing.JComboBox docField;
    private javax.swing.JFormattedTextField dogDeathDate;
    private javax.swing.JTable drugTable;
    private javax.swing.JTable healingDiagTable;
    private javax.swing.JTable healingDrugTable;
    private javax.swing.JTabbedPane healingInfo;
    private javax.swing.JLabel healingLabel;
    private javax.swing.JLabel healingName;
    private javax.swing.JTextField healingNameField;
    private javax.swing.JTable healingOperTable;
    private javax.swing.JPanel healingPanel;
    private javax.swing.JTextField healingResultField;
    private javax.swing.JPanel healingTab;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JList list;
    private javax.swing.JTextField nameBox;
    private javax.swing.JPanel newHealingPanel;
    private javax.swing.JTextField operBox;
    private javax.swing.JTable operTable;
    private javax.swing.JCheckBox payedByCard;
    private javax.swing.JButton setHealingNameButton;
    private javax.swing.JComboBox statusField;
    private javax.swing.JFormattedTextField totalPayedField;
    private javax.swing.JFormattedTextField totalPriceField;
    private javax.swing.JComboBox typeBox;
    private javax.swing.JFormattedTextField visitDateField;
    private javax.swing.JTextPane visitDescrField;
    private javax.swing.JTextField visitOtherPriceField;
    private javax.swing.JTextField visitOtherPricePayedField;
    private javax.swing.JTextField visitPriceField;
    private javax.swing.JTextField visitPricePayedField;
    private javax.swing.JTextPane visitRecomField;
    private javax.swing.JTabbedPane visitTabs;
    // End of variables declaration//GEN-END:variables
}
